package com.yang.controller;

import com.sun.istack.internal.NotNull;
import com.yang.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
public class AjaxController {

    @RequestMapping("/a1")
    public String ajax1(@NotNull String pwd1, String pwd2) {
        String msg = "";
        //模拟数据库中存在数据
        if (pwd1.equals(pwd2)) {
            msg = "success";
        }else {
            msg = "两次密码输入不一致，重新输入！！！";
            System.out.println(msg);
        }
        return msg;
    }
    @RequestMapping("/a2")
    public List<User> ajax2() {
        List<User> users = new ArrayList<User>();
        users.add(new User("杨同宇", 1, "男"));
        users.add(new User("杨同宇", 2, "男"));
        users.add(new User("陆明星", 3, "女"));
        return users;
    }
    @RequestMapping("/a3")
    public String ajax3(String name, String pwd) {
        String msg = "";
        //模拟数据库中存在数据
        if (name != null) {
            if ("admin".equals(name)) {
                msg = "OK";
            } else {
                msg = "用户名输入错误";
            }
        }
        if (pwd != null) {
            if ("123456".equals(pwd)) {
                msg = "OK";
            } else {
                msg = "密码输入有误";
            }
        }
        return msg; //由于@RestController注解，将msg转成json格式返回
    }
    @RequestMapping("/a4")
    public String ajax4(String name){
        return name+"成功了！";
    }
    @RequestMapping("/a5")
    public String ajax5(String name){
        return name+"成功了！";
    }
}

